package cn.fl.mfr.web.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.mfr.web.service.IMfrBankAccService;
import cn.fl.mfr.web.vo.MfrBankAccVO;
import cn.fl.product.service.IMfrInfoService;
import cn.fl.product.vo.MfrInfoVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.vo.SysUlFilesRecVO;
import cn.fl.upload.constant.UploadConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.framework.enums.SplInfoFileCfgEnum;
import fl.spl.facade.mfr.condition.MfrBankAccQC;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @Description: 厂商银行账户信息 控制层
 */
@Controller
@RequestMapping("/mfr/mfrbankacc")
public class MfrBankAccController extends BaseController {

	/**
	 * MfrBankAcc 服务层BEAN
	 */
	@Autowired
	private IMfrBankAccService mfrBankAccService;
	@Autowired
	private IMfrInfoService mfrInfoService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("mfr/mfrBankAcc/mfrBankAccList");
		
		String mfrId = request.getParameter("mfrId");
		String isDetail = request.getParameter("isDetail");
		String isModify = request.getParameter("isModify");
		String isCheckVerify = request.getParameter("isCheckVerify");
		String isFlow = request.getParameter("isFlow");
		String isMdfPayTyp = request.getParameter("isMdfPayTyp");


		view.addObject("mfrId", mfrId);
		view.addObject("isDetail", isDetail);
		view.addObject("isModify", isModify);
		view.addObject("isCheckVerify", isCheckVerify);
		view.addObject("isFlow", isFlow);
		view.addObject("isMdfPayTyp", isMdfPayTyp);
		BaseLogUtils.newWebLogger("到列表页面").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
				.setWarning(false)
				.info();
		return view;
	}
	
	/**
	 * 到列表详情页面
	 */
	@RequestMapping(value = "/toListPageDetail.do", method = { RequestMethod.GET})
	public ModelAndView toListPageDetail(HttpServletRequest request, HttpServletResponse response) {
		String mfrId = request.getParameter("mfrId");
		String isDetail = request.getParameter("isDetail");
		BaseLogUtils.newWebLogger("加载供应商备案账号详情列表页面").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
				.setWarning(false)
				.info();
		ModelAndView view = new ModelAndView("mfr/mfrBankAcc/mfrBankAccListDetail");
		view.addObject("mfrId", mfrId);
		view.addObject("isDetail", isDetail);
		return view;
	}
	
	/**
	 * 到新增修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {

		String mfrId = request.getParameter("mfrId");
		String id = request.getParameter("id");
		String disable = request.getParameter("disable");//是否只修改用途
		String isFlow = request.getParameter("isFlow");//是否流程附加信息页面标识
		ModelAndView view = new ModelAndView("mfr/mfrBankAcc/mfrBankAccAdd");
		String mfrNm = "";
		MfrBankAccVO mfrBankVO = null ;
		String bizTypCd = "";
		if(StringUtils.isNotEmpty(id)){
			mfrBankVO = this.mfrBankAccService.selectById(Long.valueOf(id));
			if(StringUtils.isNotEmpty(isFlow)&&"1".equals(isFlow)){
				//查询厂商信息
				if(null!=mfrBankVO && StringUtils.isNotEmpty(mfrBankVO.getMfrId())){
					MfrInfoVO mfrInfoVO = this.mfrInfoService.selectById(mfrBankVO.getMfrId(), CurrentThreadContext.getCurrentOrgCd());
					if(null!=mfrInfoVO && StringUtils.isNotEmpty(mfrInfoVO.getMfrName())){
						mfrNm = mfrInfoVO.getMfrName();
						mfrId = String.valueOf(mfrInfoVO.getId());
					}
				}
			}
			bizTypCd = mfrBankVO.getBizTypCd();
		}
		view.addObject("bizTypCd", bizTypCd);
		view.addObject("mfrNm", mfrNm);
		List<KeyValueVO> bizTypCdList = this.mfrBankAccService.searchBizTypCdList();
		List<KeyValueVO> purpCdList = this.mfrBankAccService.searchPurpCdList();
		view.addObject("bizTypCdList", bizTypCdList);
		view.addObject("purpCdListJSON", JSONArray.fromObject(purpCdList.toArray()));
		view.addObject("mfrId", mfrId);
		view.addObject("id", id);
		view.addObject("isFlow", isFlow);
		view.addObject("disable", disable);
		view.addObject("currOrgCd", CurrentThreadContext.getCurrentOrgCd());
		if(null !=  mfrBankVO){
			//查询附件信息
			String cfgCd = null ;
			String tabNm = null ;
			String cfgOrgCd = null ;
			String cfgSysCd = null ;
			String modulePath = null;
			String rootPath = null ;
			String costomerPath = null ;
			String uploadSysCd = null ;
			if(BaseConstant.IS_YESNO_NO_STR.equals(mfrBankVO.getBizTypCd())){
				//对公账户
				cfgCd = SplInfoFileCfgEnum.MFR024.getCode();
				tabNm = SplInfoFileCfgEnum.MFR024.getTableNm();
				cfgOrgCd = SplInfoFileCfgEnum.MFR024.getOrgCd();
				cfgSysCd = SplInfoFileCfgEnum.MFR024.getSysCd();
				modulePath = SplInfoFileCfgEnum.MFR024.getModulePath();
				costomerPath = SplInfoFileCfgEnum.MFR024.getUploadCostomerPath();
				rootPath = SplInfoFileCfgEnum.MFR024.getUploadRootPath();
				uploadSysCd = SplInfoFileCfgEnum.MFR024.getUploadSysCd();
			}else if(BaseConstant.IS_YESNO_YES_STR.equals(mfrBankVO.getBizTypCd())){
				//对私账户
				cfgCd = SplInfoFileCfgEnum.MFR025.getCode();
				tabNm = SplInfoFileCfgEnum.MFR025.getTableNm();
				cfgOrgCd = SplInfoFileCfgEnum.MFR025.getOrgCd();
				cfgSysCd = SplInfoFileCfgEnum.MFR025.getSysCd();
				modulePath = SplInfoFileCfgEnum.MFR025.getModulePath();
				costomerPath = SplInfoFileCfgEnum.MFR025.getUploadCostomerPath();
				rootPath = SplInfoFileCfgEnum.MFR025.getUploadRootPath();
				uploadSysCd = SplInfoFileCfgEnum.MFR025.getUploadSysCd();
			}

			view.addObject("tabNm", tabNm);
			view.addObject("cfgCd", cfgCd);
			view.addObject("cfgOrgCd", cfgOrgCd);
			view.addObject("cfgSysCd", cfgSysCd);
			view.addObject("modulePath", modulePath);
			view.addObject("costomerPath", costomerPath);
			view.addObject("rootPath", rootPath);
			view.addObject("uploadSysCd", uploadSysCd);
		}

		BaseLogUtils.newWebLogger("加载厂商备案账号新增/修改页面").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
				.setWarning(false)
				.info();
		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {

		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("mfr/mfrBankAcc/mfrBankAccModify");
		view.addObject("id", id);
		return view;
	}
	
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {

		String id = request.getParameter("id");
		String isFlow = request.getParameter("isFlow");//是否流程附加信息页面标识
		ModelAndView view = new ModelAndView("mfr/mfrBankAcc/mfrBankAccDetail");
		
		String mfrId = "";
		String mfrNm = "";
		String bizTypCd = "";
		if(StringUtils.isNotEmpty(id)){
			MfrBankAccVO mfrBankVO = this.mfrBankAccService.selectById(Long.valueOf(id));
			if(StringUtils.isNotEmpty(isFlow)&&"1".equals(isFlow)){
				//查询厂商信息
				if(null!=mfrBankVO && StringUtils.isNotEmpty(mfrBankVO.getMfrId())){
					MfrInfoVO mfrInfoVO = this.mfrInfoService.selectById(mfrBankVO.getMfrId(), CurrentThreadContext.getCurrentOrgCd());
					if(null!=mfrInfoVO && StringUtils.isNotEmpty(mfrInfoVO.getMfrName())){
						mfrNm = mfrInfoVO.getMfrName();
						mfrId = String.valueOf(mfrInfoVO.getId());
					}
				}
			}
			bizTypCd = mfrBankVO.getBizTypCd();
		}
		view.addObject("bizTypCd", bizTypCd);
		view.addObject("mfrNm", mfrNm);
		view.addObject("mfrId", mfrId);
		view.addObject("id", id);
		view.addObject("isFlow", isFlow);
		
		BaseLogUtils.newWebLogger("加载例子详细页面").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
				.setWarning(false)
				.info();
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {

		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String mfrId = request.getParameter("mfrId");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		MfrBankAccQC qc = new MfrBankAccQC();
		if (StringUtils.isNotEmpty(mfrId)) {
			qc.setMfrId(Long.valueOf(mfrId));
		}
		qc.setIsValid(BaseConstant.IS_YESNO_YES);
		qc.setIsDel(BaseConstant.IS_YESNO_NO);
		page.setCondition(qc);

		Pager pager = this.mfrBankAccService.searchListPage(page);
		List<MfrBankAccVO> list = (List<MfrBankAccVO>) pager.getResultList();
		ListPageVO<MfrBankAccVO> listPage = new ListPageVO<MfrBankAccVO>(list, pager.getTotalCount());
		BaseLogUtils.newWebLogger("加载列表页面").setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
				.setWarning(false)
				.setKeys("listPage", JSON.toJSONString(listPage))
				.info();
		return listPage;
	}
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		MfrBankAccVO entity = new MfrBankAccVO();
		try {
			entity = this.getRequestParamForMfrBankAdd(request);
			Long id = this.mfrBankAccService.add(entity);
			result.setData(id);
			BaseLogUtils.newWebLogger("新增备案账号数据成功").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setKeys("result", JSON.toJSONString(result))
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("新增备案账号数据失败，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("新增备案账号数据失败，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		MfrBankAccVO entity = new MfrBankAccVO();
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("修改备案账号信息,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return result;
		}
		try {
			entity = this.getRequestParamForMfrBankModify(request);
			entity.setId(Long.valueOf(id));
			boolean success = this.mfrBankAccService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
				BaseLogUtils.newWebLogger("修改备案账号数据失败").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			BaseLogUtils.newWebLogger("修改备案账号数据成功").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setKeys("result", JSON.toJSONString(result))
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("修改备案账号数据失败，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("修改备案账号数据失败，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {

		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			return result;
		}
		try {
			this.mfrBankAccService.removeById(Long.valueOf(id));

		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
		}
		
		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {

		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			BaseLogUtils.newWebLogger("获取数据,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return result;
		}
		
		try {
			MfrBankAccVO vo = this.mfrBankAccService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.newWebLogger("获取数据不存在").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			JSONObject reInfo = new JSONObject() ;
			if(null !=  vo){
				//查询附件信息
				String cfgCd = null ;
				String tabNm = null ;
				String cfgOrgCd = null ;
				String cfgSysCd = null ;
				String modulePath = null;
				String rootPath = null ;
				String costomerPath = null ;
				String uploadSysCd = null ;
				if(BaseConstant.IS_YESNO_NO_STR.equals(vo.getBizTypCd())){
					//对公账户
					cfgCd = SplInfoFileCfgEnum.MFR024.getCode();
					tabNm = SplInfoFileCfgEnum.MFR024.getTableNm();
					cfgOrgCd = SplInfoFileCfgEnum.MFR024.getOrgCd();
					cfgSysCd = SplInfoFileCfgEnum.MFR024.getSysCd();
					modulePath = SplInfoFileCfgEnum.MFR024.getModulePath();
					costomerPath = SplInfoFileCfgEnum.MFR024.getUploadCostomerPath();
					rootPath = SplInfoFileCfgEnum.MFR024.getUploadRootPath();
					uploadSysCd = SplInfoFileCfgEnum.MFR024.getUploadSysCd();
				}else if(BaseConstant.IS_YESNO_YES_STR.equals(vo.getBizTypCd())){
					//对私账户
					cfgCd = SplInfoFileCfgEnum.MFR025.getCode();
					tabNm = SplInfoFileCfgEnum.MFR025.getTableNm();
					cfgOrgCd = SplInfoFileCfgEnum.MFR025.getOrgCd();
					cfgSysCd = SplInfoFileCfgEnum.MFR025.getSysCd();
					modulePath = SplInfoFileCfgEnum.MFR025.getModulePath();
					costomerPath = SplInfoFileCfgEnum.MFR025.getUploadCostomerPath();
					rootPath = SplInfoFileCfgEnum.MFR025.getUploadRootPath();
					uploadSysCd = SplInfoFileCfgEnum.MFR025.getUploadSysCd();
				}

				reInfo.put("cfgCd",cfgCd);
				reInfo.put("tabNm",tabNm);
				reInfo.put("cfgOrgCd",cfgOrgCd);
				reInfo.put("cfgSysCd",cfgSysCd);
				reInfo.put("modulePath",modulePath);
				reInfo.put("costomerPath",costomerPath);
				reInfo.put("rootPath",rootPath);
				reInfo.put("uploadSysCd",uploadSysCd);
			}
			reInfo.put("mfrBankAccVO",vo);
			reInfo.put("id",id);
			result.setData(reInfo);
			BaseLogUtils.newWebLogger("获取数据").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setKeys("result", JSON.toJSONString(result))
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("根据主键获取对象失败，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.newWebLogger("根据主键获取对象失败，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}
	
	/**
	 * 获取请求参数(新增)
	 * @param request 请求
	 * @return 
	 */
	private MfrBankAccVO getRequestParamForMfrBankAdd(HttpServletRequest request)throws BaseException{
		String mfrId = request.getParameter("mfrId");
		if (StringUtils.isBlank(mfrId)) {
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "请先维护供应商基本信息!");
		}
		MfrBankAccVO mfrBankAccVO = this.getRequestParamForMfrBank(request);
		/*if(SplInfoConstant.SPL_BIZ_TYP_CD_PUBLIC.equals(mfrBankAccVO.getBizTypCd()) && CollectionUtils.isEmpty(mfrBankAccVO.getSysUlFilesRecVOList())){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "对公账户必须上传企业营业执照.");
		}*/
		mfrBankAccVO.setMfrId(Long.valueOf(mfrId));
		mfrBankAccVO.setCrtTm(new Date());
		mfrBankAccVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		return mfrBankAccVO;
	}
	
	/**
	 * 获取请求参数(修改)
	 * @param request 请求
	 * @return 
	 */
	private MfrBankAccVO getRequestParamForMfrBankModify(HttpServletRequest request)throws BaseException{
		MfrBankAccVO mfrBankAccVO = this.getRequestParamForMfrBank(request);
		
		mfrBankAccVO.setMdfTm(new Date());
		mfrBankAccVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		return mfrBankAccVO;
	}
	
	/**
	 * 获取供应商参数信息
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	private MfrBankAccVO getRequestParamForMfrBank(HttpServletRequest request)throws BaseException{
		String rcptUnt = request.getParameter("rcptUnt");//收款方
		String purpCd = request.getParameter("purpCd");//账户用途
		String accNo = request.getParameter("accNo");//收款账号
		String bkNm = request.getParameter("bkNm");//开户行
		String bkNo = request.getParameter("bkNo");//开户行行号
		String bizTypCd = request.getParameter("bizTypCd");//账号类型
		String bkRem = request.getParameter("bkRem");//备注
		String rgnPrCd = request.getParameter("rgnPrCd");//区域-省
		String rgnCyCd = request.getParameter("rgnCyCd");//区域-市
		String contTel = request.getParameter("contTel");//联系方式

		String disable = request.getParameter("disable");
		String certNo = request.getParameter("certNo");//收款人身份证号
		String bkResTel = request.getParameter("bkResTel");//银行预留手机号
		
		String mfrId = request.getParameter("mfrId");
		
		String fileParams = request.getParameter("fileParams");//附件上传信息
		
		//验证参数
		if (StringUtils.isBlank(rcptUnt)) {
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "收款方不能为空!");
		}
		if (StringUtils.isBlank(accNo) || !StringUtils.isNumeric(accNo)) {
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "收款账号不能为空,并且是数字!");
		}
		if (StringUtils.isBlank(bkNm)) {
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "开户行不能为空!");
		}
		if (StringUtils.isBlank(bkNo) || !StringUtils.isNumeric(bkNo)) {
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "开户行行号不能为空,并且是数字!");
		}
		if (StringUtils.isBlank(bizTypCd)) {
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "账号类型不能为空!");
		}else{
			if(BaseConstant.IS_YESNO_YES_STR.equals(bizTypCd) && StringUtils.isEmpty(disable)){
				if (StringUtils.isBlank(certNo) || !StringUtils.isIdCardNumber(certNo)) {
					throw new BaseException(BaseExceptionConstant.COMMON_0001, "收款方身份证号不能为空,并且是正确的身份证号格式!");
				}
				if (StringUtils.isBlank(bkResTel) || !StringUtils.checkMobileNumber(bkResTel)) {
					throw new BaseException(BaseExceptionConstant.COMMON_0001, "银行预留手机号不能为空,并且是正确的手机号格式!");
				}
			}
		}
		

		List<SysUlFilesRecVO> sysUlFilesRecVOList = new ArrayList<SysUlFilesRecVO>();
		//解析附件上传信息
		if(StringUtils.isNotEmpty(fileParams)){
			List<Map<String, String>> fileParamsList = new ArrayList<Map<String, String>>(); 
			JSONArray arry = JSONArray.fromObject(fileParams);
			for (int i = 0; i < arry.size(); i++) {
				net.sf.json.JSONObject jsonObject = arry.getJSONObject(i);
				Iterator<?> it = jsonObject.keys();  
				HashMap<String, String> hMap = new HashMap<String, String>();
				while (it.hasNext())  
				{  
					String key = String.valueOf(it.next());  
					String value = (String) jsonObject.get(key);  
					hMap.put(key, value);  
				} 
				fileParamsList.add(hMap);
			}
			for (Map<String, String> map : fileParamsList) {
				SysUlFilesRecVO sysUlFilesRecVO = new SysUlFilesRecVO();
				sysUlFilesRecVO.setFileNm(map.get("fileNm"));
				sysUlFilesRecVO.setFilePath(map.get("filePath"));
				sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH)+map.get("filePath"));
				sysUlFilesRecVO.setCrtTm(new Date());
				sysUlFilesRecVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
				//TODO 这里应该先读配置  按配置保存   这里先写死后期再改---------------Start
				sysUlFilesRecVO.setSysCd(map.get("sysCd"));
				sysUlFilesRecVO.setOrgCd(map.get("orgCd"));
				sysUlFilesRecVO.setCfgCd(map.get("cfgCd"));
				sysUlFilesRecVO.setCfgDtlCd(map.get("cfgDtlCd"));
				sysUlFilesRecVO.setTabNm(map.get("tabNm"));
				//TODO---------------------------------------------------------End
				//默认验证状态:未验证
				sysUlFilesRecVO.setAudStsCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_GRP_VALID_STATUS_CD_A));
				sysUlFilesRecVOList.add(sysUlFilesRecVO);
			}
		}
		
		
		MfrBankAccVO mfrBankAccVO = new MfrBankAccVO();
		mfrBankAccVO.setRcptUnt(rcptUnt.trim());
		mfrBankAccVO.setPurpCd(purpCd.trim());
		mfrBankAccVO.setAccNo(accNo.trim());
		mfrBankAccVO.setBkNm(bkNm.trim());
		mfrBankAccVO.setBkNo(bkNo.trim());
		mfrBankAccVO.setBizTypCd(bizTypCd);
		mfrBankAccVO.setBkRem(bkRem);
		mfrBankAccVO.setRgnPrCd(rgnPrCd);
		mfrBankAccVO.setRgnCyCd(rgnCyCd);
		mfrBankAccVO.setSysUlFilesRecVOList(sysUlFilesRecVOList);
		if(StringUtils.isNotEmpty(mfrId)){
			mfrBankAccVO.setMfrId(Long.valueOf(mfrId));
		}
		mfrBankAccVO.setContTel(contTel);
		mfrBankAccVO.setCertNo(certNo);
		mfrBankAccVO.setBkResTel(bkResTel);
		mfrBankAccVO.setIsDel(BaseConstant.IS_YESNO_NO);
		mfrBankAccVO.setIsValid(BaseConstant.IS_YESNO_YES);
		
		return mfrBankAccVO;
	}
	
	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeMfrBankById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("删除备案账号数据,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return result;
		}
		
		List<Long> idsList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idsList.add(Long.valueOf(object.toString()));
		}
		
		try {
			boolean success = this.mfrBankAccService.removeByIds(idsList);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
				BaseLogUtils.newWebLogger("删除备案账号数据失败").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			BaseLogUtils.newWebLogger("删除备案账号数据成功").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setKeys("result", JSON.toJSONString(result))
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("删除备案账号数据失败，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("删除备案账号数据失败，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}

	/**
	 * 获取图片附件配置参数
	 */
	@RequestMapping(value = "/getFileCfgInfo.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO getFileCfgInfo(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String bizTypCd = request.getParameter("bizTypCd") ;
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(bizTypCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("账号类型为空或者不存在!");
			BaseLogUtils.newWebLogger("获取附件配置信息为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return result;
		}
		//查询附件信息
		String cfgCd = null ;
		String tabNm = null ;
		String cfgOrgCd = null ;
		String cfgSysCd = null ;
		String modulePath = null;
		String rootPath = null ;
		String costomerPath = null ;
		String uploadSysCd = null ;
		if(BaseConstant.IS_YESNO_NO_STR.equals(bizTypCd)){
			//对公账户
			cfgCd = SplInfoFileCfgEnum.MFR024.getCode();
			tabNm = SplInfoFileCfgEnum.MFR024.getTableNm();
			cfgOrgCd = SplInfoFileCfgEnum.MFR024.getOrgCd();
			cfgSysCd = SplInfoFileCfgEnum.MFR024.getSysCd();
			modulePath = SplInfoFileCfgEnum.MFR024.getModulePath();
			costomerPath = SplInfoFileCfgEnum.MFR024.getUploadCostomerPath();
			rootPath = SplInfoFileCfgEnum.MFR024.getUploadRootPath();
			uploadSysCd = SplInfoFileCfgEnum.MFR024.getUploadSysCd();
		}else if(BaseConstant.IS_YESNO_YES_STR.equals(bizTypCd)){
			//对私账户
			cfgCd = SplInfoFileCfgEnum.MFR025.getCode();
			tabNm = SplInfoFileCfgEnum.MFR025.getTableNm();
			cfgOrgCd = SplInfoFileCfgEnum.MFR025.getOrgCd();
			cfgSysCd = SplInfoFileCfgEnum.MFR025.getSysCd();
			modulePath = SplInfoFileCfgEnum.MFR025.getModulePath();
			costomerPath = SplInfoFileCfgEnum.MFR025.getUploadCostomerPath();
			rootPath = SplInfoFileCfgEnum.MFR025.getUploadRootPath();
			uploadSysCd = SplInfoFileCfgEnum.MFR025.getUploadSysCd();
		}
		JSONObject reInfo = new JSONObject();
		reInfo.put("cfgCd",cfgCd);
		reInfo.put("tabNm",tabNm);
		reInfo.put("cfgOrgCd",cfgOrgCd);
		reInfo.put("cfgSysCd",cfgSysCd);
		reInfo.put("modulePath",modulePath);
		reInfo.put("costomerPath",costomerPath);
		reInfo.put("rootPath",rootPath);
		reInfo.put("uploadSysCd",uploadSysCd);
		result.setData(reInfo);
		BaseLogUtils.newWebLogger("获取附件配置信息").setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
				.setWarning(false)
				.setKeys("result", JSON.toJSONString(result))
				.info();
		return result;
	}
}

